@extends('admin.layout')

@section('content')
<div class="content-wrapper" style="min-height: 916px;">
        <div id="breadcrumbs" class="breadcrumbs">
            <ol class="breadcrumb">
            <li><a href="javascript:void();"><i class="fa fa-home"></i>&nbsp;&nbsp;后台首页</a></li>
                    
                    <li><a href="javascript:void();">会员管理</a></li>    
                    <li><a href="javascript:void();">等级列表</a></li>          
            </ol>
        </div>

        <section class="content">
       <div class="row">
            <div class="col-xs-12">
                <div class="box">
                <div class="box-header">
                   <nav class="navbar navbar-default">       
                        <div class="collapse navbar-collapse">
                            <div class="navbar-form row">
                                <a class="btn btn-primary pull-right" href="{{ asset('/admin/user/add_level') }}"><i class="fa fa-plus"></i>新增等级</a>
                            </div>
                        </div>
                    </nav>              
                 </div>     
                 <!-- /.box-header -->
                 <div class="box-body">              
                    <div class="row">
                    <div class="col-sm-12">
                      <table aria-describedby="example1_info" role="grid" class="table table-bordered table-striped dataTable" id="list-table">
                         <thead>
                           <tr role="row">
                               <th tabindex="0" class="sorting">等级</th>
                               <th tabindex="0" class="sorting">等级名称</th>
                               <th tabindex="0" class="sorting">消费额度</th>
                               <th tabindex="0" class="sorting">折扣率</th>
                               <th tabindex="0" class="sorting">等级描述</th>
                               <th tabindex="0" class="sorting">操作</th>
                           </tr>
                         </thead>
                        <tbody>
                          <tr align="center" role="row">
                             <td>1</td>
                             <td>注册会员</td>
                             <td>0.00</td>
                             <td>100%</td>
                             <td>注册会员</td>                           
                             <td>
                              <a href="/index.php/Admin/User/level/act/edit/level_id/1" class="btn btn-primary"><i class="fa fa-pencil"></i></a>
                              <a onclick="delfun(this)" data-id="1" data-url="/index.php/Admin/User/levelHandle" href="javascript:void(0)" class="btn btn-danger"><i class="fa fa-trash-o"></i></a>
                            </td>
                           </tr><tr align="center" role="row">
                             <td>2</td>
                             <td>铜牌会员</td>
                             <td>10000.00</td>
                             <td>98%</td>
                             <td>铜牌会员</td>                           
                             <td>
                              <a href="/index.php/Admin/User/level/act/edit/level_id/2" class="btn btn-primary"><i class="fa fa-pencil"></i></a>
                              <a onclick="delfun(this)" data-id="2" data-url="/index.php/Admin/User/levelHandle" href="javascript:void(0)" class="btn btn-danger"><i class="fa fa-trash-o"></i></a>
                            </td>
                           </tr><tr align="center" role="row">
                             <td>3</td>
                             <td>白银会员</td>
                             <td>30000.00</td>
                             <td>95%</td>
                             <td>白银会员</td>                           
                             <td>
                              <a href="/index.php/Admin/User/level/act/edit/level_id/3" class="btn btn-primary"><i class="fa fa-pencil"></i></a>
                              <a onclick="delfun(this)" data-id="3" data-url="/index.php/Admin/User/levelHandle" href="javascript:void(0)" class="btn btn-danger"><i class="fa fa-trash-o"></i></a>
                            </td>
                           </tr><tr align="center" role="row">
                             <td>4</td>
                             <td>黄金会员</td>
                             <td>50000.00</td>
                             <td>92%</td>
                             <td>黄金会员</td>                           
                             <td>
                              <a href="/index.php/Admin/User/level/act/edit/level_id/4" class="btn btn-primary"><i class="fa fa-pencil"></i></a>
                              <a onclick="delfun(this)" data-id="4" data-url="/index.php/Admin/User/levelHandle" href="javascript:void(0)" class="btn btn-danger"><i class="fa fa-trash-o"></i></a>
                            </td>
                           </tr><tr align="center" role="row">
                             <td>5</td>
                             <td>钻石会员</td>
                             <td>100000.00</td>
                             <td>90%</td>
                             <td>钻石会员</td>                           
                             <td>
                              <a href="/index.php/Admin/User/level/act/edit/level_id/5" class="btn btn-primary"><i class="fa fa-pencil"></i></a>
                              <a onclick="delfun(this)" data-id="5" data-url="/index.php/Admin/User/levelHandle" href="javascript:void(0)" class="btn btn-danger"><i class="fa fa-trash-o"></i></a>
                            </td>
                           </tr><tr align="center" role="row">
                             <td>6</td>
                             <td>超级VIP</td>
                             <td>200000.00</td>
                             <td>88%</td>
                             <td>超级VIP</td>                          
                             <td>
                              <a href="/index.php/Admin/User/level/act/edit/level_id/6" class="btn btn-primary"><i class="fa fa-pencil"></i></a>
                              <a onclick="delfun(this)" data-id="6" data-url="/index.php/Admin/User/levelHandle" href="javascript:void(0)" class="btn btn-danger"><i class="fa fa-trash-o"></i></a>
                            </td>
                           </tr>                           </tbody>
                         <tfoot>
                         
                         </tfoot>
                       </table>
                   </div>
              </div>
              <div class="row">
                    <div class="col-sm-6 text-left"></div>
                    <div class="col-sm-6 text-right"><div class="dataTables_paginate paging_simple_numbers"><ul class="pagination">    </ul></div></div>        
              </div>
              </div><!-- /.box-body -->
            </div><!-- /.box -->
        </div>
       </div>
   </section>
    </div>
    <script type="text/javascript">
        
        window.onload = function()
        {

            //自动清楚提示框
            setTimeout("$('#showHidden').hide( )",3000); 
            // alert($);
                $.ajaxSetup({
                    headers: {
                        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                    }
                });

                //添加事件
                
                //鼠标移入事件
                $('.std, .name').on('mouseover', function(){

                    $(this).css({cursor:'pointer', color:'blue'});
                })
                //鼠标移出事件
                $('.std, .name').on('mouseout', function(){

                    $(this).css({cursor:'default', color:'black'});
                })
                


                $('.std').on('click', function(){
                    var std = $(this);
                    var id = $(this).parent().find('.ids').html();
                    // var id = $(this ).parent().children().first().html();
                    
                    // alert(id);
                    $.post('/admin/user/ajaxUpdate',{id:id},function(data){
                        if(data =='0')
                        {
                            std.html('禁用');
                        }else if(data == '2')
                        {
                            std.html('启用');
                        }
                    },'json');

                });

                function dblClick()
                {
                    var td = $(this);
                    //获取原ID
                    var id = td.prev().html();
                    //获取原value值
                    var name= td.html();

                    var inp = $('<input type="text" />');
                    inp.val(name);

                    //将表单放到TD中
                    td.html(inp);
                    //自动对焦
                    inp.select();
                    //失去焦点
                    inp.blur(function()
                    {
                        //获取新值
                        var newName = inp.val();

                        if(name == newName)
                        {
                            // alert('你脑子有病');
                            td.html(name);
                            //添加事件
                            td.dblclick(dblClick);
                            return ;
                        }

                        //ajax
                        $.post('/admin/user/ajaxUsername',{id:id,name:newName},
                            function(data)
                            {
                                if(data == '1')
                                {
                                    alert('用户名已存在');
                                    td.html(name);
                                }else if(data == '0')
                                {
                                    td.html(newName);
                                }else
                                {
                                    alert('用户修改失败');
                                    td.html(name);
                                }
                            },'json');  
                        //添加事件
                        td.dblclick(dblClick);
                    });

                    //清除事件
                    td.unbind('dblclick');
                }

                //双击修改用户名
                $('td[class=name]').on('dblclick',dblClick);
        }

    </script>

@endsection